home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8718 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: immuno.bme.nwu.edu!johnson
  2. From: johnson@immuno.bme.nwu.edu (George Johnson)
  3. Newsgroups: comp.lang.c
  4. Subject: Running out of memory with mmap
  5. Date: 6 Mar 1996 01:38:00 GMT
  6. Organization: Northwestern University, Evanston, IL, US
  7. Message-ID: <4hiq9o$h18@news.acns.nwu.edu>
  8. NNTP-Posting-Host: immuno.bme.nwu.edu
  9. Keywords: mmap
  10.  
  11.  
  12. Hi folks--
  13.  
  14.  
  15. I have this procedure which is called a few thousand times, each time
  16. with different requests for information from different large files.  
  17. Within this procedure is :
  18.  
  19.        ....
  20.  
  21.     pa = mmap(0,fsiz,PROT_READ,MAP_PRIVATE,fpB,0);
  22.  
  23.     madvise(pa,fsiz,MADV_RANDOM);
  24.  
  25.     if ( pa == (caddr_t) -1) {
  26.        perror("mmap failed");
  27.          exit(1);
  28.      }
  29.  
  30.     .... go to the specified offset in the file, grab the info
  31.  
  32.     .... leave procedure
  33.  
  34. The size of the file(s) fpB are around 20 MB a piece.  What happens
  35. is that after 100 or so calls, the program exits saying it has run
  36. out of memory.
  37.  
  38. My question is where did the memory go?  I don't understand what is
  39. going on.  I free all malloc'ed stuff, there is little else going on
  40. in the program other than opening these big files, reading through
  41. them and grabbing out little pieces of information.
  42.  
  43. My assumption (hehehe) from reading the manual page for mmap and 
  44. munmap is that when mmap is called, it unmaps implicitly anybody
  45. occupying space 0 to fsiz, so no munmap is needed to free up (?)
  46.  
  47. I'm not sure what I'm forgetting to do.
  48.  
  49. Any suggestions would be very helpful.
  50.  
  51. Thank you,
  52.  
  53. George Johnson
  54. Kabat Database
  55.